package com.liyl.config;

import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @author zhengyixiao
 * @date 2020/8/27 16:54
 **/
@Configuration
@EnableSwagger2
@EnableSwaggerBootstrapUI
public class SwaggerBootstrapConfig {


    @Value("${spring.application.name}")
    private String appName;

    @Value("${spring.application.version}")
    private String appVersion;

    @Value("${spring.application.description}")
    private String appDesc;

    @Bean
    public Docket customDocket() {
        return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo())
                .groupName("默认接口-swaggermodels")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.liyl.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    /**
     * swagger接口文档标题
     */
    private ApiInfo apiInfo() {
        Contact contact = new Contact(appName, appDesc, "liyl_mep@163.com");
        return new ApiInfoBuilder()
                //标题
                .title(appName)
                //文档接口的描述
                .description(appDesc)
                .contact(contact)
                //版本号
                .version(appVersion)
                .build();
    }
}
